package com.qf.controller;

import com.qf.entity.Admin;
import com.qf.service.AdminService;
import com.qf.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author zdl
 * @date 2025/3/6
 */
@RestController
@RequestMapping("/employee/admin")
public class AdminController {
    @Resource
    private AdminService adminService;

    @PostMapping("/login")
    //登录
    public R<?> login(@RequestBody Admin admin, HttpSession session) {
        System.out.println(admin);
        String token = adminService.login(admin.getUsername(), admin.getPassword());
        session.setAttribute("token", token);
        return R.ok(token);
    }

    @GetMapping("/info")
    //获取用户信息
    public R<?> info(HttpSession session) {
        String token = (String) session.getAttribute("token");
        return R.ok(token);
    }
    @PostMapping("/logout")
    //退出登录
    public R<String> logout(HttpSession session) {
        session.invalidate();
        return R.ok("退出登录");
    }


}
